#!/bin/bash
#/home/pi/start.sh
sleep 5
sudo dtoverlay seeed-2mic-voicecard
sudo insmod /home/pi/workspace/ch9344driver/driver/ch9344.ko
if [ "$DISPLAY" == ":0.0" -o "$DISPLAY" == ":0" ]; then
    echo "DISPLAY=$DISPLAY"
    xrandr | grep 240x320
    if [ $? -eq 0 ];then
      echo "On spi LCD"
      vncserver-virtual
      bash -c "source /home/pi/nodejs.sh && source /home/pi/env.sh && electron  /home/pi/workspace/lepi-gui/server/server.js > /tmp/gui.log &"
      /home/pi/workspace/noVNC/utils/novnc_proxy --vnc localhost:5901 &
    else
      echo "On HDMI"
      bash -c "source /home/pi/nodejs.sh && source /home/pi/env.sh && electron  /home/pi/workspace/lepi-gui/server/server.js > /tmp/gui.log &"
      lxpanel --profile LXDE-pi &
      /home/pi/workspace/noVNC/utils/novnc_proxy --vnc localhost:5900
    fi
elif [ "$DISPLAY" == ":1" ];then
    echo "On VNC"
    lxpanel --profile LXDE-pi &

else
    echo "DISPLAY is $DISPLAY"
    export DISPLAY=":0.0"
    echo "set DISPLAY to $DISPLAY"
    netstat -tlnp | grep 8000
    if [ $? -ne 0 ];then
      echo 0
      #bash -c "source /home/pi/nodejs.sh && source /home/pi/env.sh && electron  /home/pi/workspace/lepi-gui/server/server.js > /tmp/gui.log &"
    fi
fi
xset dpms 0 0 0
xset s off
#DISPLAY=:0.1 konsole -p TerminalColumns=34 -p TerminalRows=19
# chromium-browser "http://localhost:8000/app" --kiosk --window-size=240,320
